package ${package}.${moduleName}.controller;

import cn.com.pg.instore.core.config.annotation.MultiScenarioService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import cn.com.pg.instore.core.common.dto.PageDto;
import cn.com.pg.instore.core.config.PgResponse;
import ${package}.${moduleName}.service.${ClassName}Service;
import ${package}.${moduleName}.query.${ClassName}Query;
import ${package}.${moduleName}.service.api.dto.${ClassName}Dto;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


import ${package}.${moduleName}.service.api.dto.${ClassName}Query;
import ${package}.${moduleName}convertor.${ClassName}Convertor;
import ${package}.${moduleName}.respository.${ClassName}Repository;
import ${package}.${moduleName}.service.${ClassName}Service;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
* <p>
* ${tableComment}
* </p>
* @author ${author}
* @since ${date}
*/
@SpringBootTest(classes = PgSpaCounterStoreApplication.class)
@Configurable
@AutoConfigureMockMvc
class ${ClassName}ControllerTest {

    private final static String BASE_URL = "/api/v1/${functionName}";

    @Autowired
    private MockMvc mockMvc;
    @Autowired
    private ${ClassName}Service ${className}Service;
    @MockBean
    private ${ClassName}Repository ${className}Repository;
    @MockBean
    private ${ClassName}Convertor ${className}Convertor;


    @Test
    void page() throws Exception {
        ${ClassName}Query query = new ${ClassName}Query();
        when(${className}Repository.page(any())).thenReturn(new Page<>());
        mockMvc.perform(get(BASE_URL+"/page")
                        .contentType(MediaType.APPLICATION_JSON)
                        .content(JSONObject.toJSONString(query)))
                .andExpect(status().isOk());
    }

    @Test
    void get${ClassName}ById() throws Exception {
        mockMvc.perform(get(BASE_URL+"/id")
                        .contentType(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk());
    }

    @Test
    void save() throws Exception {
        mockMvc.perform(post(BASE_URL)
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"id\":\"1111\"}"))
                .andExpect(status().isOk());
    }

    @Test
    void update() throws Exception {
        mockMvc.perform(put(BASE_URL)
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("{\"id\":\"1111\"}"))
                .andExpect(status().isOk());
    }

    @Test
    void deleteByIds() throws Exception {
        mockMvc.perform(delete(BASE_URL)
                        .contentType(MediaType.APPLICATION_JSON)
                        .content("[\"1\",\"2\"]"))
                .andExpect(status().isOk());
    }
}